FROM golang as build

ENV GOPROXY=https://goproxy.io

ADD . /qimages

WORKDIR /qimages

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api_server

FROM alpine:3.7

ENV MYSQL_DSN=""
ENV PHOTO_PREFIX=""
ENV PHOTO_PATH=""
ENV GIN_MODE="release"
ENV LOG_FILE=""
ENV PORT=9000

RUN echo "http://mirrors.aliyun.com/alpine/v3.7/main/" > /etc/apk/repositories && \
    apk update && \
    apk add ca-certificates && \
    echo "hosts: files dns" > /etc/nsswitch.conf && \
    mkdir -p /www

WORKDIR /www

COPY --from=build /qimages/api_server /usr/bin/api_server
ADD ./config.yaml /www/config.yaml

RUN chmod +x /usr/bin/api_server

ENTRYPOINT ["api_server"]